from Tkinter import *
from tkSimpleDialog import *
import tkMessageBox

class ClassesFrame(Frame):
    """
    Represents the frame that provides a user interface to access a project's CRCs information.
    """
    
    def __init__(self, parentControl, listener):
        Frame.__init__(self, parentControl)
        self.parentControl = parentControl
        self.listener = listener
        
        label = Label(self, text="Classes:")
        label.grid()

        self.classesListbox = Listbox(self, selectmode = SINGLE)
        self.classesListbox.grid(row=1)
        
        button = Button(self, text="Nouvelle classe", command=self.createClass)
        button.grid(row = 2)
    
        button = Button(self, text="Modifier classe", command=self.modifyClasses)
        button.grid(row = 3)
        
        self.crcFrame = Frame(self)
        self.crcFrame.grid(column = 0, rowspan = 3)
        
    def createClass(self):
        self.listener.onMakeClassForm(None)
    
    def modifyClasses(self):
        if len(self.classesListbox.curselection()) == 0:
            tkMessageBox.showerror("Erreur", "Vous devez choisir une classe existante pour pouvoir la modifier.")
        else: 
            self.listener.onMakeClassForm(self.classesListbox.get(ACTIVE))
    
    def setClassesListbox(self, name):
        self.classesListbox.insert(0, name)
        